{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Q# notebooks #\n",
    "\n",
    "This notebook will show you how to use IQ# to write your own quantum application notebooks.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Compiling Q# operations"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "An operation is the basic unit of quantum execution in Q#. It is roughly equivalent to a function in C or C++ or Python, or a static method in C# or Java.\n",
    "\n",
    "IQ#, the Q# Jupyter kernel, allows you to write Q# operations directly on a code cell and compile them by running the cell (pressing  Ctrl/⌘+Enter). For example:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/json": "[\"HelloQ\"]",
      "text/html": [
       "<ul><li>HelloQ</li></ul>"
      ],
      "text/plain": [
       "HelloQ"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "operation HelloQ(name: String) : Unit {\n",
    "\n",
    "    // The following line will simply write a message to the console:\n",
    "    Message($\"Hello {name}!\");\n",
    "\n",
    "}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "When you **Run** the cell, Q# compiles the code and returns the name of the operations it found. \n",
    "In this case, it found only one operation (`HelloQ`). \n",
    "\n",
    "If the compiler detects any errors, it will instead show the list of errors in the output. For example:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/snippet:(5,5): error QS5022: No identifier with that name exists.\n",
      "/snippet:(9,12): error QS6211: Unexpected argument tuple. Expecting an argument of type String.\n"
     ]
    }
   ],
   "source": [
    "operation InvalidQ() : Unit {\n",
    "\n",
    "    // The `FooBar` operation doesn't exist, so the following line\n",
    "    // will generate a `No variable with that name exists.` error:\n",
    "    FooBar(\"Hello again!\");\n",
    "    \n",
    "    // `Message` takes only one string argument, so the following line\n",
    "    // will generate a `Unexpected argument tuple.` error:\n",
    "    Message(1, 2);\n",
    "}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Q# operations can call other operations previously defined; they can also call all the operations defined in the \n",
    "[Microsoft.Quantum.Intrinsic](https://docs.microsoft.com/qsharp/api/qsharp/microsoft.quantum.intrinsic) and \n",
    "[Microsoft.Quantum.Canon](https://docs.microsoft.com/qsharp/api/qsharp/microsoft.quantum.canon) namespaces (like [Message](https://docs.microsoft.com/qsharp/api/qsharp/microsoft.quantum.intrinsic.message)).\n",
    "\n",
    "For example, you can create a new operation that calls the previously compiled `HelloQ`:\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/json": "[\"HelloAndres\"]",
      "text/html": [
       "<ul><li>HelloAndres</li></ul>"
      ],
      "text/plain": [
       "HelloAndres"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "operation HelloAndres() : Unit {\n",
    "    HelloQ(\"Andres\");\n",
    "}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "They can also use all [Q# standard library](https://docs.microsoft.com/qsharp/api/) operations defined in other namespaces by importing the namespace using the `open` statement. For example, to use [`PI`](https://docs.microsoft.com/qsharp/api/prelude/microsoft.quantum.math.pi) you would need to open the ` Microsoft.Quantum.Math` namespace; optionally you can call the operation providing its fully qualified name, for example:\n",
    " "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/json": "[\"HelloPi\"]",
      "text/html": [
       "<ul><li>HelloPi</li></ul>"
      ],
      "text/plain": [
       "HelloPi"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "open Microsoft.Quantum.Math;\n",
    "\n",
    "operation HelloPi() : Unit {\n",
    "    let pi = Microsoft.Quantum.Convert.DoubleAsString(PI());\n",
    "    HelloQ(pi);\n",
    "}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You can define multiple operations in a single cell and use any valid Q# code, for example:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/json": "[\"PrepareRandomMessage\",\"SetMinus\",\"SetPlus\"]",
      "text/html": [
       "<ul><li>PrepareRandomMessage</li><li>SetMinus</li><li>SetPlus</li></ul>"
      ],
      "text/plain": [
       "PrepareRandomMessage, SetMinus, SetPlus"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "open Microsoft.Quantum.Math;\n",
    "\n",
    "/// # Summary\n",
    "/// Sets the qubit's state to |+⟩\n",
    "operation SetPlus(q: Qubit) : Unit {\n",
    "    Reset(q);\n",
    "    H(q);\n",
    "}\n",
    "\n",
    "/// # Summary\n",
    "/// Sets the qubit's state to |-⟩\n",
    "operation SetMinus(q: Qubit) : Unit {\n",
    "    Reset(q);\n",
    "    X(q);\n",
    "    H(q);\n",
    "}\n",
    "\n",
    "/// # Summary\n",
    "/// Randomly prepares the qubit into |+⟩ or |-⟩\n",
    "operation PrepareRandomMessage(q: Qubit) : Unit {\n",
    "\n",
    "    let choice = RandomInt(2);\n",
    "\n",
    "    if (choice == 0) {\n",
    "        Message(\"Prepared |-⟩\");\n",
    "        SetMinus(q);\n",
    "    } else {\n",
    "        Message(\"Prepared |+⟩\");\n",
    "        SetPlus(q);\n",
    "    }\n",
    "}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "and create other operations that uses them:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/json": "[\"NextRandomBit\",\"TestPrepareQubits\"]",
      "text/html": [
       "<ul><li>NextRandomBit</li><li>TestPrepareQubits</li></ul>"
      ],
      "text/plain": [
       "NextRandomBit, TestPrepareQubits"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "open Microsoft.Quantum.Diagnostics;\n",
    "open Microsoft.Quantum.Measurement;\n",
    "\n",
    "operation NextRandomBit() : Result {\n",
    "    using (q = Qubit()) {\n",
    "        SetPlus(q);\n",
    "        return MResetZ(q);\n",
    "    }\n",
    "}\n",
    "\n",
    "operation TestPrepareQubits() : Result {\n",
    "    mutable r = Zero;\n",
    "    \n",
    "    using (qubits = Qubit[5]) {\n",
    "        ApplyToEach(PrepareRandomMessage, qubits);\n",
    "        DumpMachine();\n",
    "        \n",
    "        set r = Measure([PauliX, PauliX, PauliX, PauliX, PauliX], qubits);\n",
    "        \n",
    "        ResetAll(qubits);\n",
    "    }\n",
    "    \n",
    "    return r;\n",
    "}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Simulating Q# operations\n",
    "\n",
    "\n",
    "Once a Q# operation has been successfully compiled, you can use the `%simulate` command to simulate it. For example:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello 3.14159265358979!\n"
     ]
    },
    {
     "data": {
      "application/json": "{\"@type\":\"tuple\"}",
      "text/plain": [
       "()"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%simulate HelloPi"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/json": "1",
      "text/plain": [
       "One"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%simulate NextRandomBit"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`%simulate` will print any console output on the notebook, and it will return the operation's return value. If the operation returns `Unit` it prints `()`, otherwise it prints the actual value.\n",
    "\n",
    "`%simulate` only accepts operations that take no arguments. If you want to call an operation that accepts parameters, like `HelloQ`, create a wrapper operation that calls it with the corresponding values, like `HelloPi`.\n",
    "\n",
    "As mentioned, all messages are printed on the notebook; this includes calls to [`DumpMachine`](https://docs.microsoft.com/en-us/qsharp/api/prelude/microsoft.quantum.extensions.diagnostics.dumpmachine):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Prepared |-⟩\n",
      "Prepared |+⟩\n",
      "Prepared |-⟩\n",
      "Prepared |-⟩\n",
      "Prepared |+⟩\n",
      "# wave function for qubits with ids (least to most significant): 0;1;2;3;4\n",
      "∣ 0❭:\t 0.176777 +  0.000000 i\t == \t*                    [ 0.031250 ]     --- [  0.00000 rad ]\n",
      "∣ 1❭:\t-0.176777 +  0.000000 i\t == \t*                    [ 0.031250 ] ---     [  3.14159 rad ]\n",
      "∣ 2❭:\t 0.176777 +  0.000000 i\t == \t*                    [ 0.031250 ]     --- [  0.00000 rad ]\n",
      "∣ 3❭:\t-0.176777 +  0.000000 i\t == \t*                    [ 0.031250 ] ---     [  3.14159 rad ]\n",
      "∣ 4❭:\t-0.176777 +  0.000000 i\t == \t*                    [ 0.031250 ] ---     [  3.14159 rad ]\n",
      "∣ 5❭:\t 0.176777 +  0.000000 i\t == \t*                    [ 0.031250 ]     --- [  0.00000 rad ]\n",
      "∣ 6❭:\t-0.176777 +  0.000000 i\t == \t*                    [ 0.031250 ] ---     [  3.14159 rad ]\n",
      "∣ 7❭:\t 0.176777 +  0.000000 i\t == \t*                    [ 0.031250 ]     --- [  0.00000 rad ]\n",
      "∣ 8❭:\t-0.176777 +  0.000000 i\t == \t*                    [ 0.031250 ] ---     [  3.14159 rad ]\n",
      "∣ 9❭:\t 0.176777 +  0.000000 i\t == \t*                    [ 0.031250 ]     --- [  0.00000 rad ]\n",
      "∣10❭:\t-0.176777 +  0.000000 i\t == \t*                    [ 0.031250 ] ---     [  3.14159 rad ]\n",
      "∣11❭:\t 0.176777 +  0.000000 i\t == \t*                    [ 0.031250 ]     --- [  0.00000 rad ]\n",
      "∣12❭:\t 0.176777 +  0.000000 i\t == \t*                    [ 0.031250 ]     --- [  0.00000 rad ]\n",
      "∣13❭:\t-0.176777 +  0.000000 i\t == \t*                    [ 0.031250 ] ---     [  3.14159 rad ]\n",
      "∣14❭:\t 0.176777 +  0.000000 i\t == \t*                    [ 0.031250 ]     --- [  0.00000 rad ]\n",
      "∣15❭:\t-0.176777 +  0.000000 i\t == \t*                    [ 0.031250 ] ---     [  3.14159 rad ]\n",
      "∣16❭:\t 0.176777 +  0.000000 i\t == \t*                    [ 0.031250 ]     --- [  0.00000 rad ]\n",
      "∣17❭:\t-0.176777 +  0.000000 i\t == \t*                    [ 0.031250 ] ---     [  3.14159 rad ]\n",
      "∣18❭:\t 0.176777 +  0.000000 i\t == \t*                    [ 0.031250 ]     --- [  0.00000 rad ]\n",
      "∣19❭:\t-0.176777 +  0.000000 i\t == \t*                    [ 0.031250 ] ---     [  3.14159 rad ]\n",
      "∣20❭:\t-0.176777 +  0.000000 i\t == \t*                    [ 0.031250 ] ---     [  3.14159 rad ]\n",
      "∣21❭:\t 0.176777 +  0.000000 i\t == \t*                    [ 0.031250 ]     --- [  0.00000 rad ]\n",
      "∣22❭:\t-0.176777 +  0.000000 i\t == \t*                    [ 0.031250 ] ---     [  3.14159 rad ]\n",
      "∣23❭:\t 0.176777 +  0.000000 i\t == \t*                    [ 0.031250 ]     --- [  0.00000 rad ]\n",
      "∣24❭:\t-0.176777 +  0.000000 i\t == \t*                    [ 0.031250 ] ---     [  3.14159 rad ]\n",
      "∣25❭:\t 0.176777 +  0.000000 i\t == \t*                    [ 0.031250 ]     --- [  0.00000 rad ]\n",
      "∣26❭:\t-0.176777 +  0.000000 i\t == \t*                    [ 0.031250 ] ---     [  3.14159 rad ]\n",
      "∣27❭:\t 0.176777 +  0.000000 i\t == \t*                    [ 0.031250 ]     --- [  0.00000 rad ]\n",
      "∣28❭:\t 0.176777 +  0.000000 i\t == \t*                    [ 0.031250 ]     --- [  0.00000 rad ]\n",
      "∣29❭:\t-0.176777 +  0.000000 i\t == \t*                    [ 0.031250 ] ---     [  3.14159 rad ]\n",
      "∣30❭:\t 0.176777 +  0.000000 i\t == \t*                    [ 0.031250 ]     --- [  0.00000 rad ]\n",
      "∣31❭:\t-0.176777 +  0.000000 i\t == \t*                    [ 0.031250 ] ---     [  3.14159 rad ]\n"
     ]
    },
    {
     "data": {
      "application/json": "1",
      "text/plain": [
       "One"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%simulate TestPrepareQubits"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Estimating resources\n",
    "\n",
    "The `%estimate` command lets you estimate the resources a given quantum operation will need to execute, without actually executing the operation. Similar to `%simulate` it takes the name of a no-arguments operation. However, `%estimate` does not keep track of the qubit's state and will not return the output of the operation, instead it returns the estimated values of how many resources, like Qubits and CNOT gates, the corresponding operation will use:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/json": "{\"CNOT\":0.0,\"QubitClifford\":10.0,\"R\":0.0,\"Measure\":11.0,\"T\":0.0,\"Depth\":0.0,\"Width\":5.0,\"BorrowedWidth\":0.0}",
      "text/html": [
       "<ul><li>[CNOT, 0]</li><li>[QubitClifford, 10]</li><li>[R, 0]</li><li>[Measure, 11]</li><li>[T, 0]</li><li>[Depth, 0]</li><li>[Width, 5]</li><li>[BorrowedWidth, 0]</li></ul>"
      ],
      "text/plain": [
       "[CNOT, 0], [QubitClifford, 10], [R, 0], [Measure, 11], [T, 0], [Depth, 0], [Width, 5], [BorrowedWidth, 0]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%estimate TestPrepareQubits"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To learn more about resources estimation, take a look at [The ResourcesEstimator Target Machine](https://docs.microsoft.com/en-us/quantum/machines/resources-estimator?) documentation."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## The Workspace\n",
    "\n",
    "The notebook uses the folder it lives on disk to define a workspace. It will try to compile all the Q# files (i.e. all files with a `.qs` extension) it finds under the current folder and will make the operations it finds available to operations in the notebook. For example, the [Operations.qs](/Operations.qs) file in this folder defines two operations:\n",
    "* Microsoft.Quantum.Samples.IsMinus\n",
    "* Microsoft.Quantum.Samples.IsPlus\n",
    "\n",
    "To get the list of operations defined in the workspace, you can use the `%workspace` command:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/json": "[\"Microsoft.Quantum.Samples.IsMinus\",\"Microsoft.Quantum.Samples.IsPlus\"]",
      "text/html": [
       "<ul><li>Microsoft.Quantum.Samples.IsMinus</li><li>Microsoft.Quantum.Samples.IsPlus</li></ul>"
      ],
      "text/plain": [
       "Microsoft.Quantum.Samples.IsMinus, Microsoft.Quantum.Samples.IsPlus"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%workspace"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "These operations can be used in this notebook, for example:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/json": "[\"CheckPlus\"]",
      "text/html": [
       "<ul><li>CheckPlus</li></ul>"
      ],
      "text/plain": [
       "CheckPlus"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "open Microsoft.Quantum.Samples;\n",
    "\n",
    "operation CheckPlus() : Bool {\n",
    "    mutable result = false;\n",
    "    \n",
    "    using (q = Qubit()) {\n",
    "        SetPlus(q);\n",
    "        set result = IsPlus(q);\n",
    "        \n",
    "        Reset(q);\n",
    "    }\n",
    "\n",
    "    return result;\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/json": "true",
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%simulate CheckPlus"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To pick up any changes you make to a Q# file in the workspace, use `%workspace reload`. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/json": "[\"Microsoft.Quantum.Samples.IsMinus\",\"Microsoft.Quantum.Samples.IsPlus\"]",
      "text/html": [
       "<ul><li>Microsoft.Quantum.Samples.IsMinus</li><li>Microsoft.Quantum.Samples.IsPlus</li></ul>"
      ],
      "text/plain": [
       "Microsoft.Quantum.Samples.IsMinus, Microsoft.Quantum.Samples.IsPlus"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%workspace reload"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Getting Help ##\n",
    "\n",
    "Q# supports adding documentation to operations via comments in the code. When such documentation exists, you can access it from the notebook by adding a question mark before or after the operation name on a code cell, for example:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/json": "{\"name\":\"Microsoft.Quantum.Intrinsic.X\",\"kind\":1,\"source\":\"/home/jovyan/.dotnet/tools/.store/microsoft.quantum.iqsharp/0.9.1908.2906/microsoft.quantum.iqsharp/0.9.1908.2906/tools/netcoreapp3.0/any/Microsoft.Quantum.Intrinsic.dll\",\"documentation\":\" # Summary\\n Applies the Pauli $X$ gate.\\n\\n \\\\begin{align}\\n     \\\\sigma_x \\\\mathrel{:=}\\n     \\\\begin{bmatrix}\\n         0 & 1 \\\\\\\\\\\\\\\\\\n         1 & 0\\n     \\\\end{bmatrix}.\\n \\\\end{align}\\n\\n # Input\\n ## qubit\\n Qubit to which the gate should be applied.\"}",
      "text/html": [
       "<h4><i class=\"fa fas fa-terminal\"></i> Microsoft.Quantum.Intrinsic.X <a href=\"/home/jovyan/.dotnet/tools/.store/microsoft.quantum.iqsharp/0.9.1908.2906/microsoft.quantum.iqsharp/0.9.1908.2906/tools/netcoreapp3.0/any/Microsoft.Quantum.Intrinsic.dll\"><i class=\"fa fas fa-code\"></i></a></h4><h1>Summary</h1>\n",
       "<p>Applies the Pauli $X$ gate.</p>\n",
       "<p>\\begin{align}\n",
       "\\sigma_x \\mathrel{:=}\n",
       "\\begin{bmatrix}\n",
       "0 &amp; 1 \\\\\n",
       "1 &amp; 0\n",
       "\\end{bmatrix}.\n",
       "\\end{align}</p>\n",
       "<h1>Input</h1>\n",
       "<h2>qubit</h2>\n",
       "<p>Qubit to which the gate should be applied.</p>\n"
      ],
      "text/plain": [
       "Microsoft.Quantum.Intrinsic.X"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Microsoft.Quantum.Intrinsic.X?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This documentation is available for any operations in the Prelude, Canon and Workspace, or even those defined locally in the notebook:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/json": "{\"name\":\"PrepareRandomMessage\",\"kind\":1,\"source\":\"/workspaces/Quantum/Samples/src/IntroToIQSharp/obj/__snippets__.dll\",\"documentation\":\" # Summary\\n Randomly prepares the qubit into |+⟩ or |-⟩\"}",
      "text/html": [
       "<h4><i class=\"fa fas fa-terminal\"></i> PrepareRandomMessage <a href=\"/workspaces/Quantum/Samples/src/IntroToIQSharp/obj/__snippets__.dll\"><i class=\"fa fas fa-code\"></i></a></h4><h1>Summary</h1>\n",
       "<p>Randomly prepares the qubit into |+⟩ or |-⟩</p>\n"
      ],
      "text/plain": [
       "PrepareRandomMessage"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "PrepareRandomMessage?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Other commands ##"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### `%who`\n",
    "\n",
    "`%who` returns the list of all local and workspace operations available."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/json": "[\"CheckPlus\",\"HelloAndres\",\"HelloPi\",\"HelloQ\",\"Microsoft.Quantum.Samples.IsMinus\",\"Microsoft.Quantum.Samples.IsPlus\",\"NextRandomBit\",\"PrepareRandomMessage\",\"SetMinus\",\"SetPlus\",\"TestPrepareQubits\"]",
      "text/html": [
       "<ul><li>CheckPlus</li><li>HelloAndres</li><li>HelloPi</li><li>HelloQ</li><li>Microsoft.Quantum.Samples.IsMinus</li><li>Microsoft.Quantum.Samples.IsPlus</li><li>NextRandomBit</li><li>PrepareRandomMessage</li><li>SetMinus</li><li>SetPlus</li><li>TestPrepareQubits</li></ul>"
      ],
      "text/plain": [
       "CheckPlus, HelloAndres, HelloPi, HelloQ, Microsoft.Quantum.Samples.IsMinus, Microsoft.Quantum.Samples.IsPlus, NextRandomBit, PrepareRandomMessage, SetMinus, SetPlus, TestPrepareQubits"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%who"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### `%package`\n",
    "\n",
    "`%package` allows you to load nuget packages and makes available any Q# operations defined on them. For example, to use the operations from [Q#'s Quantum Chemistry Library](https://docs.microsoft.com/en-us/quantum/libraries/chemistry/?view=qsharp-preview), you must load the [Microsoft.Quantum.Chemistry](https://www.nuget.org/packages/Microsoft.Quantum.Chemistry/) nuget package:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/json": "[\"Microsoft.Quantum.Standard::0.9.1908.2906\",\"Microsoft.Quantum.Chemistry::0.9.1908.2906\"]",
      "text/html": [
       "<ul><li>Microsoft.Quantum.Standard::0.9.1908.2906</li><li>Microsoft.Quantum.Chemistry::0.9.1908.2906</li></ul>"
      ],
      "text/plain": [
       "Microsoft.Quantum.Standard::0.9.1908.2906, Microsoft.Quantum.Chemistry::0.9.1908.2906"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%package Microsoft.Quantum.Chemistry"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`%package` returns the list of nuget packages currently loaded and their version."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### `%version`\n",
    "\n",
    "`%version` simply returns the current versions of IQ# and of Jupyter Core (a library used by IQ#):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/json": "{\"rows\":[{\"@type\":\"@tuple\",\"Item1\":\"iqsharp\",\"Item2\":\"0.9.1908.2906\"},{\"@type\":\"@tuple\",\"Item1\":\"Jupyter Core\",\"Item2\":\"1.1.14623.0\"}]}",
      "text/html": [
       "<table><thead><tr><th>Component</th><th>Version</th></tr></thead><tbody><tr><td>iqsharp</td><td>0.9.1908.2906</td></tr><tr><td>Jupyter Core</td><td>1.1.14623.0</td></tr></tbody></table>"
      ],
      "text/plain": [
       "Component    Version\n",
       "------------ -------------\n",
       "iqsharp      0.9.1908.2906\n",
       "Jupyter Core 1.1.14623.0\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "%version"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Q#",
   "language": "qsharp",
   "name": "iqsharp"
  },
  "language_info": {
   "file_extension": ".qs",
   "mimetype": "text/x-qsharp",
   "name": "qsharp",
   "version": "0.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
